package day03;

import java.util.InputMismatchException;
import java.util.Scanner;

public class MaxOfTwoIntegers {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int num1 = 0, num2 = 0;
        //开始默认两次输入无效
        boolean isValidInput1 = false, isValidInput2 = false;

        while (!isValidInput1) {
            System.out.print("请输入第一个整数（整数类型）: ");
            try {
                num1 = scanner.nextInt();
                isValidInput1 = true;
            } catch (InputMismatchException e) {
                System.out.println("输入错误，请输入整数！");
                scanner.next(); // 清除输入缓冲区中的错误输入
            }
        }

        while (!isValidInput2) {
            System.out.print("请输入第二个整数（整数类型）: ");
            try {
                num2 = scanner.nextInt();
                isValidInput2 = true;
            } catch (InputMismatchException e) {
                System.out.println("输入错误，请输入整数！");
                scanner.next(); // 清除输入缓冲区中的错误输入
            }
        }

        // 判断并输出两个整数中的最大值
        int max = Math.max(num1, num2);
        System.out.println("两个整数中的最大值是：" + max);

        scanner.close();
    }
}
